package com.springbook;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class EditBikeController implements Controller {

	private RentABike facade;
	
	public RentABike getFacade() {
		return facade;
	}

	public void setFacade(RentABike facade) {
		this.facade = facade;
	}

	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		String serialNo=arg0.getParameter("serialNo");
		if (serialNo==null) {
			System.out.println("serial number was null");
			return new ModelAndView("listBikes.jsp");
		}
		else {
			System.out.println("serial number was "+serialNo);
			Bike b = facade.getBike(serialNo);
			if (b!=null) {
				return new ModelAndView("editBike.jsp", "bike", b);
			}
		}
		System.out.println("no such bike for serial number "+serialNo);
		return new ModelAndView("listBikes.jsp");
	}

}
